package com.cdream.gateway.handler;


import com.cdream.common.core.exception.CaptchaException;
import com.cdream.common.core.web.domain.AjaxResult;
import com.cdream.gateway.service.ValidateCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

import java.io.IOException;

/**
 * 验证码获取
 */
@RestController
@RequestMapping("/capcha")
public class ValidateCodeHandler {
    @Autowired
    private ValidateCodeService validateCodeService;

    @GetMapping("/code")
    public Mono<AjaxResult> createCapcha() {
        AjaxResult ajax;
        try {
            ajax = validateCodeService.createCapcha();
        } catch (CaptchaException | IOException e) {
            return Mono.error(e);
        }
        return Mono.just(ajax);
    }
}
